//
//  AEMyExchangeRootViewController.m
//  AESOLAR_IOS
//
//  Created by Bin Tang on 2024/10/13.
//  Copyright © 2024 Mr.Wang. All rights reserved.
//

#import "AEMyExchangeRootViewController.h"
#import "AEMyExchangeRootViewModel.h"
#import "TYZBaseTableViewController.h"
#import "TYZBaseCollectionViewController.h"
#import "AEMyExchangeViewController.h"

@interface AEMyExchangeRootViewController () <TYZPageViewControllerDelegate, TYZPageViewControllerDataSource>

@property (nonatomic, strong) AEMyExchangeRootViewModel *viewModel;

@end

@implementation AEMyExchangeRootViewController

- (void)dealloc
{
    debugMethod();
}

- (void)initWithVar
{
    [super initWithVar];
    
}

- (void)initWithViewModel
{
    _viewModel = [AEMyExchangeRootViewModel new];
    
}

- (void)initWithNavBar
{
    [super initWithNavBar];
    
    [self initWithBackButton];
    
    self.navigationItem.title = self.viewModel.title;
    
    /*
    if (@available(iOS 15.0, *))
    {
        UINavigationBarAppearance *nav = [UINavigationBarAppearance new];
        [nav configureWithOpaqueBackground]; // 重置背景和阴影颜色
        // 背景色
        nav.backgroundColor = kWhiteColor;
        
        nav.shadowImage = [[UIImage alloc] init];
        
        // 去掉半透明效果
        nav.backgroundEffect = nil;
        
        // 去掉导航栏阴影（如果不设置clear，导航栏底下会有一条阴影线）
        nav.shadowColor = [UIColor clearColor];
        
//        nav.titleTextAttributes = @{NSForegroundColorAttributeName:navInfo.titleColor, NSFontAttributeName:navInfo.titleFont};
        self.navigationController.navigationBar.scrollEdgeAppearance = nav; // 带scroll滑动的页面
        self.navigationController.navigationBar.standardAppearance = nav; // 常规页面
        
        return;
    }
    
    // 导航栏背景
    [self.navigationController.navigationBar setBarTintColor:kWhiteColor];
    
    // navBar title Color font
//    [self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:navInfo.titleColor, NSFontAttributeName:navInfo.titleFont}];
    
    // 去除自带的顶部阴影
    self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];

    // 设置导航栏控制器颜色
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:kWhiteColor] forBarMetrics:UIBarMetricsDefault];
    
    if ([self.navigationController.navigationBar respondsToSelector:@selector(setTranslucent:)])
    {
        // 设置导航栏是否具有透明度这个功能
        // 在iOS7以后，默认为YES。{控件从（0，0）点开始，设置为NO,则从nav底部（0，64）开始}；
//        self.navigationBar.translucent = NO;
    }
    */
}

- (void)initWithSubView
{
    self.dataSource = self;
    self.delegate = self;
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [super initWithSubView];
}

+ (TYZPageConfigration *)setupConfig
{
    TYZPageConfigration *config = [TYZPageConfigration defaultConfigration];
    config.pageStyle = TYZPageStyleTop;
    config.headerViewCouldScale = NO;
    config.headerViewScaleMode = TYZPageHeaderViewScaleModeTop;
//    config.headerViewCouldScrollPage = NO;
    config.showTabbar = NO;
    config.showNavigation = YES;
    config.aligmentModeCenter = NO;
    config.lineWidthEqualFontWidth = YES; // 变为平分时 是否需要线条宽度等于字体宽度 默认 NO
    config.showBottomLine = NO;
    config.scrollMenu = NO;
//    config.itemMargin = 20;
    
    config.aligmentModeCenter = NO;
    config.lineHeight = 2;
//    config.lineWidth = 30;
    config.lineColor = kThemeColor;
    
//    config.cutOutHeight = kWDWorkOrderTopViewHeight;
//    config.suspenOffsetY = kWDWorkOrderTopViewHeight;//NAVBAR_HEIGHT_STATUS; // 设置悬浮停顿偏移量
    
    config.itemFont = [UIFont systemFontOfSize:14 weight:UIFontWeightBold];
    config.selectedItemFont = [UIFont systemFontOfSize:15 weight:UIFontWeightBold];
    config.normalItemColor = [UIColor colorWithHexString:@"#999999"];
    config.selectedItemColor = [UIColor colorWithHexString:@"#333333"];;
    config.scrollViewBackgroundColor = kWhiteColor;
    
    return config;
}

+ (NSArray *)setupMenuTitles {
    return @[@"全部", @"待领取", @"已领取"];
}

+ (NSArray *)setupViewControllers:(NSDictionary *)param {
    NSArray *titles = [self setupMenuTitles];
    NSMutableArray *vcs = @[].mutableCopy;
    for (int i=0; i<titles.count; i++) {
        NSString *title = titles[i];
        AEMyExchangeViewController *vc = [[AEMyExchangeViewController alloc] init];
        vc.statusName = title;
        [vcs addObject:vc];
    }
    return vcs;
}


#pragma mark - TYZPageViewControllerDelegate, TYZPageViewControllerDataSource
- (UIScrollView *)pageViewController:(TYZPageViewController *)pageViewController pageForIndex:(NSInteger)index
{
    UIViewController *vc = pageViewController.controllerList[index];
    
    if ([vc isKindOfClass:[TYZBaseTableViewController class]])
    {
        return ((TYZBaseTableViewController *)vc).baseTableView;
    }
    else if ([vc isKindOfClass:[TYZBaseCollectionViewController class]]) {
        return ((TYZBaseCollectionViewController *)vc).baseCollectionView;;
    }
    return nil;
}

- (void)pageViewController:(TYZPageViewController *)pageViewController contentOffsetY:(CGFloat)contentOffsetY progress:(CGFloat)progress
{
    
}

- (void)pageViewController:(TYZPageViewController *)pageViewController didScrollMenuItem:(UIButton *)itemButton index:(NSInteger)index
{
    
}

@end
